#include <cppunit/config/SourcePrefix.h>
#include "TestDesignEntityTable.h"

void TestDesignEntityTable::setUp() {
}

void TestDesignEntityTable::tearDown() {
}

CPPUNIT_TEST_SUITE_REGISTRATION( TestDesignEntityTable );

void TestDesignEntityTable::testAddGetAssignDe(){
	DesignEntityTable deTable = DesignEntityTable();
	
	Node procNode(new Procedure(0));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Adding non-Assign node is not allowed", false, deTable.addAssignDe(&procNode));

	Node assignNode1(new Assign(),1);
	Node assignNode2(new Assign(),2);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Adding Assign node successfully", true, deTable.addAssignDe(&assignNode1));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Adding Assign node successfully", true, deTable.addAssignDe(&assignNode2));

	vector<Node*> nodes =  deTable.getAssignDe();
	int size = nodes.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Total 2 items", 2, size);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("first item is assignNode1", &assignNode1, nodes.at(0));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("second item is assignNode2", &assignNode2, nodes.at(1));
}

void TestDesignEntityTable::testAddGetConstantDe(){
	DesignEntityTable deTable = DesignEntityTable();
	
	Node assignNode(new Assign(), 1);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Adding non-Constant node is not allowed", false, deTable.addConstantDe(&assignNode));

	Node constantNode1(new Constant(2),1);
	Node constantNode2(new Constant(4),1);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Adding Constant node successfully", true, deTable.addConstantDe(&constantNode1));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Adding Constant node successfully", true, deTable.addConstantDe(&constantNode2));

	vector<Node*> nodes =  deTable.getConstantDe();
	int size = nodes.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Total 2 items", 2, size);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("first item is constantNode1", &constantNode1, nodes.at(0));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("second item is constantNode2", &constantNode2, nodes.at(1));
}

void TestDesignEntityTable::testAddGetIfDe(){
	DesignEntityTable deTable = DesignEntityTable();
	
	Node constantNode(new Constant(10), 1);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Adding non-If node is not allowed", false, deTable.addIfDe(&constantNode));

	Node ifNode1(new If(),2);
	Node ifNode2(new If(),10);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Adding If node successfully", true, deTable.addIfDe(&ifNode1));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Adding If node successfully", true, deTable.addIfDe(&ifNode2));

	vector<Node*> nodes =  deTable.getIfDe();
	int size = nodes.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Total 2 items", 2, size);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("first item is ifNode1", &ifNode1, nodes.at(0));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("second item is ifNode2", &ifNode2, nodes.at(1));
}

void TestDesignEntityTable::testAddGetWhileDe(){
	DesignEntityTable deTable = DesignEntityTable();
	
	Node ifNode(new If(), 5);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Adding non-While node is not allowed", false, deTable.addWhileDe(&ifNode));

	Node whileNode1(new While(),5);
	Node whileNode2(new While(),10);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Adding While node successfully", true, deTable.addWhileDe(&whileNode1));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Adding While node successfully", true, deTable.addWhileDe(&whileNode2));

	vector<Node*> nodes =  deTable.getWhileDe();
	int size = nodes.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Total 2 items", 2, size);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("first item is whileNode1", &whileNode1, nodes.at(0));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("second item is whileNode2", &whileNode2, nodes.at(1));
}